<div style="padding: 15px;">
    <table id="projectTable" lay-filter="staffTable"></table>
</div>
<script type="text/html" id="bar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs" lay-event="calc">计算薪资</a>
</script>
<script type="text/javascript">
    layui.use('table', function() {
        let table = layui.table;
        let Data;
        table.render({
            elem: '#projectTable'
            , url: '/staff/list'
            , cols: [
                [
                    {field: 'staffId', title: '员工编号', align: 'center'}
                    , {field: 'staffName', title: '员工名称', align: 'ceter'}
                    , {field: 'staffPassword', title: '员工密码', align: 'center'}
                    , {field: 'staffType', title: '类型',templet: function(res){
                        if (res.staffType === 0){
                            return "学徒员工"
                        }
                        if (res.staffType === 1){
                            return "熟手员工"
                        }
                        if (res.staffType === 2){
                            return "前台"
                        }
                        if (res.staffType === 3){
                            return "主管"
                        }
                        if (res.staffType === 4){
                            return "管理员"
                        }
                    }, align: 'center'}
                    , {title: '操作', align: 'center', width: 200, toolbar: '#bar'}
                ]
            ]
            , page: true
        });

        table.on('tool(staffTable)', function (obj) { //tool是工具条事件名，参数是table原始容器的lay-filter属性值
            let layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'edit') {
                layer.open({
                    type: 2,
                    title: '更新项目信息',
                    shadeClose: true,
                    shade: false,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['893px', '600px'],
                    content: '/router/updateStaff/'+obj.data.staffId,
                });
            }
            if (layEvent === 'calc') {
                //管理员或者前台不需要计算
                if(obj.data.staffType === 4 || obj.data.staffType === 2) {
                    layer.msg('该员工不需要计算', {icon: 5});
                    return
                }
                layer.open({
                    type: 2,
                    title: '计算薪资',
                    shadeClose: true,
                    shade: false,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['893px', '600px'],
                    content: '/router/calc/'+obj.data.staffId,
                });
            }
        });

    });
</script>